package logic

import (
	"context"
	"course_srv/course"
	"course_srv/internal/svc"
	"course_srv/models/mysql"

	"github.com/zeromicro/go-zero/core/logx"
)

type CommentListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCommentListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CommentListLogic {
	return &CommentListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *CommentListLogic) CommentList(in *course.CommentListRequest) (*course.CommentListResponse, error) {

	c := mysql.Comment{}
	list, _ := c.CommentList(int(in.UserId))
	var slice []*course.CommentList
	for _, comment := range list {
		slice = append(slice, &course.CommentList{
			Content: comment.Content,
			S:       int32(comment.Score),
		})
	}
	return &course.CommentListResponse{List: slice}, nil
}
